package com.marketingexpert.controller.streammgnt;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import com.marketingexpert.exception.MarketingExpertException;
import com.marketingexpert.service.streammgnt.StreamService;
import com.marketingexpert.util.Resources;

public class DeleteTabController implements Controller {

	private StreamService streamService;
	private static Logger logger = Logger.getLogger(DeleteTabController.class);
	
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		response.setContentType("application/text;charset=GBK"); 
		response.setHeader("Pragma", "No-cache"); 
		response.setHeader("Cache-Control", "no-cache"); 
		response.setHeader("Cache-Control", "no-store"); 
		response.setDateHeader("Expires", 0);  
		PrintWriter out = response.getWriter();
		
		String tabId = request.getParameter("tabId");
		
		try {
			getStreamService().deleteTabById(Integer.parseInt(tabId));
		} catch(MarketingExpertException e){
			logger .error(Resources.getString("Stream.deleteTabByIdFailed"));
			throw e;
		}
		out.print(Resources.getString("Stream.deleteTabByIdSuccess"));
		return null;
	}

	public StreamService getStreamService() {
		return streamService;
	}

	public void setStreamService(StreamService streamService) {
		this.streamService = streamService;
	}

	
}
